		$.ajax({
   			type: "POST",
   			async: false,
   			url: ctxPath+"/workflow/form!getHtml.action",
   			data: $("#appConfig-template-form").serialize(),
   			success: function(msg) {
   				//解析json
   				var data = eval(msg);
   				//显示html代码
   				$("#formTempDiv").append(data);
   				$('#formTempDiv').find("tr>th").droppable({
   					accept: ".divclass",
   					drop: function(event, ui) {
   						$(this).html($(ui.draggable).html());
   					}
   				});
   			}
   		});
		
		function formatTable() {
			var oldObj = $('#formTempDiv');
			var obj = $(oldObj).clone(true);

			//删除table原有属性，新增class类名
			$(obj).find('table').each(function(i, table) {
				var attrNames = [];
				var attrs = table.attributes;
				for (var j = 0; j < attrs.length; j++) {
					attrNames[j] = attrs[j].nodeName;//table.removeAttribute(attrs[j].nodeName),不可直接删除,此时attrs长度已变
				}
				for (var n = 0; n < attrNames.length; n++){
					table.removeAttribute(attrNames[n]);
				}
				$(table).addClass("table table-bordered");
			});
			
			$(obj).find('th').each(function(i, th) {
				$(th).removeAttr('class');
				var item = $(th).find("div.item");
				if(item.size() > 0){
					var style = item.attr("style");
					var td = "<td style=\"" + style + "\"><div class='form-content'>" + $(th).find("div.item-data").html() + "</div></td>";
					$(th).after(td);
					$(th).attr('style',style);
					var thead = $(th).find('label').html();
					$(th).empty().append(thead);
				}
			});
			
			var htmlSource = $(obj).html();
			return htmlSource;
		}
		
		$("#sub_table").click(function(){
			var HTMLSource = formatTable();
			if(HTMLSource.indexOf("td") > -1){
				HTMLSource = HTMLSource.replace(new RegExp("'", "gm"), function() {
					var un;
					return '^';
			    });
				var en_HTML = encodeURIComponent(HTMLSource);
				en_HTML = en_HTML.replace(new RegExp("%", "gm"), function() {
					return '~';
				});
				$.ajax({
					type: "POST",
					url: ctxPath+"/workflow/form!saveHtml.action",
					data: "HTMLSource=" + en_HTML + "&appId=" + $('input[name="appId"]').val(),
					success: function(msg) {
						dialog.alert(msg);
					}
				});
			}else{
				dialog.alert("请把左侧的字段拖拽到表格内再'生成表单'!");
			}
		});
		
		function preview() {
			var htmlSource = formatTable();
			htmlSource = htmlSource.replace(new RegExp("'", "gm"), function() {
				var un;
				return '^';
			})
			var en_HTML = encodeURIComponent(htmlSource);
			en_HTML = en_HTML.replace(new RegExp("%", "gm"), function() {
				return '~';
			});

			var href = ctxPath + "/workflow/form!preview.action";
			$("#htmlSource").val(en_HTML);
			document.formPreview.action = href;
			document.formPreview.submit();
		}